from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver import ActionChains


driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.baidu.com")
time.sleep(2)

# set_element = driver.find_element(By.XPATH, "//span[text()='设置']")
# # 鼠标悬停
# # set_element = driver.find_element(By.XPATH, "//span[text()='设置']")
# ActionChains(driver).move_to_element(set_element).perform()
# # 双击
# ActionChains(driver).double_click(set_element).perform()
# # 右击
# ActionChains(driver).context_click(set_element).perform()
baidu_input = driver.find_element(By.ID, "kw")
# 输入坚果
baidu_input.send_keys("坚果")
time.sleep(1)
# 删除-果
baidu_input.send_keys(Keys.BACK_SPACE)
# 输入空格
baidu_input.send_keys(Keys.SPACE)
time.sleep(1)
# 输入python
baidu_input.send_keys('python')
time.sleep(1)
# 全选
baidu_input.send_keys(Keys.CONTROL, 'a')
# 复制
baidu_input.send_keys(Keys.CONTROL, "c")
time.sleep(1)
for i in range(3):
    baidu_input.send_keys(Keys.CONTROL, 'v')
    time.sleep(1)
time.sleep(3)
driver.quit()